package com.lmt.controller;

import com.lmt.entity.User;
import com.lmt.feign.ProviderFeignClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户Controller
 * Date 2018/06/28
 *
 * @author MT-Lin
 */
@SuppressWarnings("ALL")
@RestController
public class UserController {

    private final ProviderFeignClient providerFeignClient;

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    public UserController(ProviderFeignClient providerFeignClient) {
        this.providerFeignClient = providerFeignClient;
    }

    @GetMapping("/findUserById")
    public User findUserById(@RequestParam(name = "id") String id){
        logger.warn("consumer-feign-multiple-params->findUserById:id={}", id);
        return providerFeignClient.findUserById(id);
    }

    @GetMapping(value = "/getUserByRequestParam")
    public User getUserByRequestParam(String id, String username){
        logger.warn("consumer-feign-multiple-params->getUserByRequestParam:id={},username={}", id, username);
        return providerFeignClient.getUserByRequestParam(id, username);
    }

    @GetMapping(value = "/getUserByMap")
    public User getUserByMap(String id, String username){
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("username", username);
        logger.warn("consumer-feign-multiple-params->getUserByMap:id={},username={}", id, username);
        return providerFeignClient.getUserByMap(map);
    }

    @PostMapping(value = "/getUserByEntity")
    public User getUserByEntity(@RequestBody User user){
        logger.warn("consumer-feign-multiple-params->getUserByEntity:{}", user);
        return providerFeignClient.getUserByEntity(user);
    }
}
